import SwiftUI

// RegisterPage
// 注册界面小窗口

struct RegisterWindow: View {
    @Environment(\.modelContext) private var modelContext
    
    @State private var passwordRepeat: String = ""
    
    @State private var largeTitleText: String = "欢迎"
    
    @Binding var phoneNumberInput: String
    @Binding var passwordInput: String
    
    @Binding var registerStatus: Bool
    
    var body: some View {
        VStack {
            Text(largeTitleText)
                .font(largeTitleText == "欢迎" ? .largeTitle : .title2)
                .foregroundColor(largeTitleText == "欢迎" ? .black : .red)
                .padding(.vertical, 20)
            
            RegisterInput(phoneNumberInput: $phoneNumberInput,
                          passwordInput: $passwordInput,
                          passwordRepeat: $passwordRepeat)
                .padding(.bottom, 20)
            
            RegisterButton(phoneNumberInput: $phoneNumberInput,
                           passwordInput: $passwordInput,
                           passwordRepeat: $passwordRepeat,
                           largeTitleText: $largeTitleText,
                           registerStatus: $registerStatus)
                .modelContext(modelContext)
                .padding(.bottom, 20)
        }
        .background(.white)
        .frame(maxWidth: 360)
        .cornerRadius(10)
    }
}

#Preview {
    @State var phoneNumberInput: String = ""
    @State var passwordInput: String = ""
    
    return RegisterWindow(phoneNumberInput: $phoneNumberInput,
                          passwordInput: $passwordInput,
                          registerStatus: .constant(false))
}
